package com.fyp.ptma.model;

import java.io.Serializable;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 * 
 * @author YahyaArshad
 * 
 */
@Entity(name = "DownloaderGroup")
public class Group implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Long id;

	private String groupName;

	private User user;

	private Date date = new Date(System.currentTimeMillis());

	private List<Downloader> downloaders = new ArrayList<Downloader>();

	@ManyToMany(fetch = FetchType.EAGER)
	@Cascade(value = { CascadeType.ALL })
	@Column(nullable = true)
	@JoinTable(name = "GroupDetail", joinColumns = { @JoinColumn(referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(referencedColumnName = "id") })
	public List<Downloader> getDownloaders() {
		return downloaders;
	}

	public void setDownloaders(List<Downloader> downloaders) {
		this.downloaders = downloaders;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(referencedColumnName = "id")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Id
	@GeneratedValue
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getGroupName() {
		return groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	public Date getDate() {
		return date;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return groupName;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Group(String groupName) {
		super();
		this.groupName = groupName;
	}

	public Group() {
		super();

	}

}
